﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilsCache;
using UtilsORM;
using UtilsORM.MySqlData;

namespace GatewayServerService.Data
{
    public class DBIotDeviceVariableCache
    {



        /// <summary>
        /// 缓存增加 获取变量列表
        /// </summary>
        /// <param name="cguid"></param>
        /// <returns></returns>
        public iot_device_model_variable getVariableByKey(string key)
        {

            iot_device_model_variable list = UtilMemoryCacheHelper.get<iot_device_model_variable>("getVariableByKey" + key);
            if (list == null)
            {
                EFYihongIotContext ef = new EFYihongIotContext();
                list = ef.iot_device_model_variable.Where(c => c.v_key == key).FirstOrDefault();
                UtilMemoryCacheHelper.set("getVariableByKey" + key, list, 10);
            }
            return list;
        }
        public string getValueTypeByKey(string key)
        {
            string valueTypeByKey = UtilMemoryCacheHelper.get<string>("getValueTypeByKey" + key);
            if (valueTypeByKey == null)
            {
                EFYihongIotContext ef = new EFYihongIotContext();
                iot_device_model_variable variable = ef.iot_device_model_variable.Where(c => c.v_key == key).FirstOrDefault();
                if (variable != null)
                {
                    valueTypeByKey = variable.v_value_type;
                    UtilMemoryCacheHelper.set("getValueTypeByKey" + key, valueTypeByKey, 10);
                }
            }
            return valueTypeByKey;
        }
    }
}
